<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
/*
	积分、余额日志
*/
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	$return['types']=$this->credit_type;
	$return['adds']=array(
		'0'=>'消费',
		'1'=>'获得',
		'2'=>'提现',
	);
	$types2=array();
	foreach($return['types'] as $k=>$tv){
		$types2[]=array('id'=>$k,'title'=>$tv);
	}
	$return['types2']=$types2;
	$return['adds2']=array(
		array('id'=>0,'title'=>'消费'),
		array('id'=>1,'title'=>'获得'),
		array('id'=>2,'title'=>'提现'),
	);
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:10;
	$params=array('uniacid'=>$_SESSION['uniacid'],'plugin'=>'jy_newganfee');
	$return['params']=array();
	//会员ID
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	//会员ID
	if(!empty($_RQ['tixian'])){
		$params['mid']=pdo_getcolumn('core_member_cash',array('id'=>$_RQ['id']),'mid');
		$return['params']['mid']=$params['mid'];
		$params['type']=2;
		$return['params']['type']=2;
	}
	//日志类型，1积分，2余额
	if(!empty($_RQ['type'])){
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=$_RQ['type'];
	}
	//日志种类，1增加，0减少
	if(isset($_RQ['is_add'])){
		$params['is_add']=intval($_RQ['is_add']);
		$return['params']['is_add']=$_RQ['is_add'];
	}
	//时间范围
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['createtime']=$time_range;
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$list=pdo_getslice('core_credit_log',$params,array($pindex,$psize),$total,array(),'','id desc');
	foreach($list as &$item){
		$item['plugin']=pdo_getcolumn('core_plugins',array('name'=>$item['plugin']),'title');
		$item['op_midname']=pdo_getcolumn('core_users',array('id'=>$item['op_mid']),'name');
		$item['op_midname']=$item['op_midname']?:'无';
		$item['member']=cfc('core')->member_show($item['mid']);
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'余额返现记录'),
			array('op'=>'baolist','title'=>'保证金返现记录'),
		),
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'mid','title'=>'会员id','type'=>'string'),
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			array('name'=>'type','title'=>'返现类型','type'=>'radio','options'=>'types'),
			array('name'=>'is_add','title'=>'类型','type'=>'radio','options'=>'adds'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
			array('name'=>'plugin','title'=>'插件','type'=>'string'),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
			array('name'=>'op_midname','title'=>'操作员','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
		)),
		'search'=>array(
			array('type'=>'select','width'=>15,'title'=>'积分类型','name'=>'type','options'=>'types2'),
			array('type'=>'select','width'=>15,'title'=>'日志类型','name'=>'is_add','options'=>'adds2'),
			array('type'=>'choose','width'=>15,'title'=>'会员id','name'=>'mid','action'=>'core/member.get_member/','choose_title'=>'选择会员'),
			array('type'=>'time_range','width'=>18,'title'=>'创建时间','name'=>'createtime','help'=>''),
		),
	);
	exi($return);
}
if($_RQ['op']=='baolist'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'type'=>7);
	if(isset($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=intval($_RQ['mid']);
	}
	if($_RQ['times']){
		$params['times']=$_RQ['times'];
		$return['params']['times']=$_RQ['times'];
	}
	if($_RQ['dayid']){
		$params['dayid']=$_RQ['dayid'];
		$return['params']['dayid']=$_RQ['dayid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	if($_RQ['psize']){
		$_SESSION['psize']=$_RQ['psize'];
	}
	$psize = $_SESSION['psize']?:10;
	$list=pdo_getslice('jy_newganfee_log',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$pinggoods=pdo_get('jy_newganfee_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['pingid']));
			$item['goods']=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$pinggoods['goodsid']),array('title','image'));
			/*if($item['type']==4 && $item['status']==1 && $item['createtime']<=1622079145){
				if($item['gift_type']>=1){
					if($item['gift_type']==2){
						$this->model('member')->recharge($item['mid'],$item['other_credit_fee'],7,'返现保证金');
					}else{
						model('core/member')->member_credit($item['mid'],'credit'.$item['other_type'],$item['other_credit_fee'],true,'jy_newganfee','拼单参与额外大奖');
					}
				}
			}*/
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'余额返现记录'),
			array('op'=>'baolist','title'=>'保证金返现记录'),
		),
		'list'=>array('data'=>'list','total'=>$total,'psize'=>$psize,'edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			//array('name'=>'goods.title','title'=>'拼团商品','type'=>'string'),
			//array('name'=>'goods.image','title'=>'拼团商品图片','type'=>'image'),
			array('name'=>'type','title'=>'类型','type'=>'radio','options'=>'types'),
			array('name'=>'msg','title'=>'备注','type'=>'string'),
			array('name'=>'dayid','title'=>'日期','type'=>'string'),
			array('name'=>'timeid','title'=>'时间段','type'=>'string'),
			array('name'=>'createtime','title'=>'预约时间','type'=>'time'),
		)),
		'search'=>array(
			array('name'=>'dayid','title'=>'日期','type'=>'string','width'=>15),
			array('name'=>'times','title'=>'时间段','type'=>'string','width'=>15),
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		),
	);
	$return['types']=$this->log_type;
	$return['htmls']=$htmls;	
	exi($return);
}